package com.lengyu.iottransfer.gateway.common;

public enum HttpResultStatus {

    /**
     * 请求成功
     */
    SUCCESS(20000, "处理成功"),

    /**
     * 请求失败
     */
    FAILED(20001, "处理失败"),

    /**
     * 用户
     */
    NO_AUTH(20002, "访问此资源需要完整的身份验证"),

    /**
     * token无效
     */
    TOKEN_VALID(20003, "token无效");


    private int code;
    private String msg;

    HttpResultStatus(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public static String getMsg(int code) {
        for (HttpResultStatus status : values()) {
            if (status.getCode() == code) {
                return status.getMsg();
            }
        }
        return null;
    }

    public static HttpResultStatus getByCode(int code) {
        for (HttpResultStatus status : values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        return null;
    }

    public HttpResultStatus setMsg(String msg) {
        this.msg = msg;
        return this;
    }
}
